π§© Dynamic Programming
DP is just recursion with memoization, recognized. Identify the state (what defines a unique subproblem) and the recurrence (how subproblem answers combine). Everything else is implementation detail.
This category contains 38 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.
π§ Key Patternsβ
- 1D DP β House Robber, Climbing Stairs, Decode Ways. State = index.
- 2D DP β LCS, Edit Distance, Interleaving. State = (i, j) on two strings.
- Knapsack β 0/1 vs Unbounded. Capacity + item index as state.
- Interval DP β Matrix Chain, Burst Balloons. State = (l, r). Try every split point.
- Grid DP β Unique Paths, Min Path Sum. State = (i, j) cell.
- Bitmask DP β TSP, assignment. State = (mask, last). Sets up to ~20 elements.
- State Machine β Stock problems. State = (day, holding, transactions_left).
β οΈ Common Pitfallsβ
- Starting from tabulation when memoized recursion is clearer. Write recursion first, then add memo.
- Wrong base case (empty string, zero capacity).
- Forgetting space optimization: many 2D DPs only need the previous row.
π Study Resourcesβ
πΊ Videosβ
- Aditya Verma β DP Master Playlist (best in class)
- NeetCode β 1-D DP
- MIT 6.006 β DP Lectures 19β22
π Booksβ
- Introduction to Algorithms (CLRS) β Ch. 15 (Dynamic Programming) β the canonical reference
- Algorithms β Erickson (free) β Ch. 3 β best intuition-builder anywhere: https://jeffe.cs.illinois.edu/teaching/algorithms/
- Competitive Programming Handbook β Laaksonen (free) β https://cses.fi/book/book.pdf
π Articles & Referencesβ
π» All Dynamic Programming Problemsβ
Best Time to Buy and Sell Stock
LeetCode 121 | Difficulty: Easy
Best Time to Buy and Sell Stock II
LeetCode 122 | Difficulty: Medium
Best Time to Buy and Sell Stock III
LeetCode 123 | Difficulty: Hard
Burst Balloons
LeetCode 312 | Difficulty: Hard
Climbing Stairs
LeetCode 70 | Difficulty: Easy
Coin Change
LeetCode 322 | Difficulty: Medium
Decode Ways
LeetCode 91 | Difficulty: Medium
Dungeon Game
LeetCode 174 | Difficulty: Hard
Edit Distance
LeetCode 72 | Difficulty: Medium
Frog Jump
LeetCode 403 | Difficulty: Hard
House Robber
LeetCode 198 | Difficulty: Medium
House Robber II
LeetCode 213 | Difficulty: Medium
House Robber III
LeetCode 337 | Difficulty: Medium
Keyboard Row
LeetCode 500 | Difficulty: Easy
Longest Common Subsequence
LeetCode 1250 | Difficulty: Medium
Longest Palindromic Subsequence
LeetCode 516 | Difficulty: Medium
Maximal Rectangle
LeetCode 85 | Difficulty: Hard
Maximal Square
LeetCode 221 | Difficulty: Medium
Maximum Number of Balloons
LeetCode 1297 | Difficulty: Easy
Min Cost Climbing Stairs
LeetCode 747 | Difficulty: Easy
Minimum Path Sum
LeetCode 64 | Difficulty: Medium
Minimum Window Subsequence
LeetCode Link
Partition Array into Disjoint Intervals
LeetCode 951 | Difficulty: Medium
Partition Equal Subset Sum
LeetCode 416 | Difficulty: Medium
Partition List
LeetCode 86 | Difficulty: Medium
Partition to K Equal Sum Subsets
LeetCode 698 | Difficulty: Medium
Pascal's Triangle
LeetCode 118 | Difficulty: Easy
Pascal's Triangle II
LeetCode 119 | Difficulty: Easy
Perfect Squares
LeetCode 279 | Difficulty: Medium
Regular Expression Matching
LeetCode 10 | Difficulty: Hard
Target Sum
LeetCode 494 | Difficulty: Medium
Triangle
LeetCode 120 | Difficulty: Medium
Unique Paths
LeetCode 62 | Difficulty: Medium
Unique Paths II
LeetCode 63 | Difficulty: Medium
Valid Triangle Number
LeetCode 611 | Difficulty: Medium
Wildcard Matching
LeetCode 44 | Difficulty: Hard
Word Break
LeetCode 139 | Difficulty: Medium
Word Break II
LeetCode 140 | Difficulty: Hard